<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            font-family: cursive;
        }
    </style>
</head>

<body>


    <script>

        var num = prompt("请输入金字塔的层数：");

        for (var i = 0; i < num; i++) {

            var nbsp = num - i - 1;
            for (var j = 0; j < nbsp; j++) {
                document.write("&nbsp;");
            }
                           // 0 1 2 3 4
                           // 0 * 2 - 1
            var star = (i+1)*2-1;  // 1 3 5 7 9
            for (var k = 0; k < star; k++) {
                document.write("*");
            }

            document.write("<br>");

        }



/*        
for(var i = 0;i<5;i++){
    console.log(123);
    console.log(i);
    for(var s = 0;s<5;s++){
        console.log(s);
        for(var x = 0;x<3;x++){
            console.log(x);
        }
    }
    console.log(i+1);
    for(var j = 0;j<10;j++){
        console.log("abc");
    }
    console.log(456);
}
*/



    </script>




</body>

</html>